package com.zyb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyb.mapper.GradeMapper;
import com.zyb.pojo.Grade;
import com.zyb.service.GradeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {

    //条件查询带分页
    @Override
    public IPage<Grade> getGradePage(Integer pageNo, Integer pageSize, String gradeName) {
        IPage<Grade> iPage=new Page<>(pageNo,pageSize);
        QueryWrapper<Grade> wrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(gradeName)){
            wrapper.like("name",gradeName);
        }
        wrapper.orderByDesc("id");
        IPage<Grade> gradeIPage = baseMapper.selectPage(iPage, wrapper);
        return gradeIPage;
    }

    //查询全部
    @Override
    public List<Grade> getGrades() {
        return baseMapper.selectList(null);
    }
}
